-
Notifications
You must be signed in to change notification settings - Fork 303
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
switch to new package index, decompress into .tar in javascript #2024
Conversation
0ffbb12
to
653acab
Compare
653acab
to
1400739
Compare
1400739
to
5768cef
Compare
5768cef
to
60ed77d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my comments, also can you describe how you've tested this in the PR description for future reference?
Some changes needed but accepting to unblock.
class ArrayBufferReader { | ||
constructor(arrayBuffer) { | ||
this.arrayBuffer = arrayBuffer; | ||
} | ||
|
||
read(offset, buf){ | ||
// buf is a Uint8Array | ||
const size = this.arrayBuffer.byteLength; | ||
if (offset >= size || offset < 0) { | ||
return 0; | ||
} | ||
let toCopy = buf.length; | ||
if (size - offset < toCopy) { | ||
toCopy = size - offset; | ||
} | ||
buf.set(new Uint8Array(this.arrayBuffer, offset, toCopy)); | ||
return toCopy; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should tar.js instead be changed to expect an ArrayBuffer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, then we would have to expose an ArrayBuffer instead of a PackagesTarReader, not sure if we want that big of a refactor. This interface is meant to match exactly what PackagesTarReader does in JSG.
loading.push(req); | ||
} | ||
|
||
console.log("Loading " + loading.join(", ")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should these console.logs be removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I kept them there to match the original prints from the pyodide package loader. I'd prefer to keep them for now so we have more visibility on performance in testing.
src/pyodide/internal/loadPackage.js
Outdated
|
||
console.log("Loading " + loading.join(", ")); | ||
|
||
await Promise.all(loadPromises).then((buffers) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit
await Promise.all(loadPromises).then((buffers) => { | |
const buffers = await Promise.all(loadPromises); |
src/pyodide/internal/python.js
Outdated
@@ -194,6 +195,7 @@ async function prepareWasmLinearMemory(Module) { | |||
} | |||
|
|||
export async function loadPyodide(lockfile, indexURL) { | |||
console.log("loading pyodide"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
console.log("loading pyodide"); |
} | ||
}); | ||
|
||
console.log("Loaded " + loading.join(", ")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
console.log("Loaded " + loading.join(", ")); |
loading.push(req); | ||
} | ||
|
||
console.log("Loading " + loading.join(", ")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
console.log("Loading " + loading.join(", ")); |
|
||
/** | ||
* A small bundle contains just a single package. The entire bundle will be overlaid onto site-packages. | ||
* A small bundle can basically be thought of as a wheel. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should it just be called addSingleWheel
then?
* @param {List<String>} soFiles A list of .so files contained in the big bundle | ||
* @param {List<String>} requirements canonicalized list of packages to pick from the big bundle | ||
*/ | ||
addBigBundle(tarInfo, soFiles, requirements) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder why we have this split. Isn't addSmallBundle
just the same as addBigBundle with a single requirement? Why separate them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The structure of a big bundle is different from a small bundle. A big bundle contains one folder for each package, with each folder containing the structure of a wheel. A small bundle contains just the wheel for a single package, not contained within a folder.
|
||
let LOAD_WHEELS_FROM_R2 = true; | ||
let requirementsInBigBundle = new Set([...STDLIB_PACKAGES]); | ||
if(bigTarInfo.children.size > 10) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if(bigTarInfo.children.size > 10) { | |
if (bigTarInfo.children.size > 10) { |
} | ||
|
||
function disabledLoadPackage() { | ||
throw new Error("We only use loadPackage in workerd"); | ||
throw new Error("pyodide.loadPackage is disabled"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
throw new Error("pyodide.loadPackage is disabled"); | |
throw new Error("pyodide.loadPackage is disabled because packages are embedded in the binary"); |
60ed77d
to
8810715
Compare
0f63bb7
to
74ba19f
Compare
a7b8f61
to
5559c51
Compare
* switch to new package index, decompress into .tar in javascript * switch to new index, perform full package installation in JavaScript * Address nits * Fix circular import issue
how to test:
bazel build //... && time ./bazel-bin/src/workerd/server/workerd test samples/pyodide-langchain/config.capnp | ts
Without this change: 27s loading packages, 155s CPU time, 63s total wall time
With this change: 1s loading packages, 100s CPU time, 40s total wall time